package com.woniu.teachmall04.controller;

import com.woniu.teachmall04.entity.Address;
import com.woniu.teachmall04.service.AddressService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    @GetMapping("/all")
    public ResponseEntity<List<Address>> getAllAddresses(HttpSession session) {
        //获取session里loginUser的id
        Integer userId = (Integer) session.getAttribute("loginUser");
        List<Address> addresses = addressService.getAllAddresses(userId);
        return ResponseEntity.ok(addresses);
    }
}